<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'getlist';
$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['isrecommend']){
		$params['isrecommend']=$_RQ['isrecommend'];
		$return['params']['isrecommend']=$_RQ['isrecommend'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$list=pdo_getslice('jy_weishop_live_room',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$this->status=array('待启用','已启用');
		foreach($list as &$item){
			$item['image']=$item['image']?tomedia($item['image']):'';
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['livetime']=date('Y/m/d H:i:s',$item['livetime']);
			$item['statustitle']=$this->status[$item['status']];
			$goods_ids=array();
			foreach($item['goodsid'] as $gv){
				$goods_ids[$gv['id']]=$gv['id'];
			}
			$item['goods_ids']=$goods_ids;
		}
	}
	$return['list']=$list?$list:array();
	$return['params']['page'] =$pindex;
	$return['post']=array('goods_ids'=>'');
	$return['member']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','mobile','avatar','nickname'));
	$return['member']['avatar']=$return['member']['avatar']?tomedia($return['member']['avatar']):'';
	$roomids=pdo_getall('jy_weishop_live_room',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id','id');
	if($roomids){
		$roomids=array_keys($roomids);
		$total_count=pdo_count('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'status <'=>4,'roomid'=>$roomids),'id');
		$mytotalfee=pdo_getsum('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'status <'=>4,'roomid'=>$roomids),'total_price');
		$mytotalfee=price($mytotalfee*$sale_live['tichengrate']/100);
	}else{
		$total_count=0;
	}
	$return['mytotalfee']=$mytotalfee?:'0.00';
	$return['redmodal']=array(
		'title'=>'主播收入明细',
		'myallfee'=>$return['mytotalfee'],
		'total_count'=>$total_count
	);
	set_html('title','我的直播间');
	exi($return);
}
if($_RQ['op']=='setgoodstorooms'){
	$post=get_postdata();
	$goods_ids=array();
	$post['goods_ids']=str_array($post['goods_ids']);
	foreach($post['goods_ids'] as $id){
		    if($id>0){
		        $goods_ids[]=$id;
		    }
	}
	$goods=array();
	foreach($goods_ids as $id){
			$goods[]=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),array('id','title','price','image'));
	}
	$data=array(
			'goodsid'=>ijson_encode($goods),
	);
	pdo_update('jy_weishop_live_room',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['id']));
	exi('导入成功');
}